{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "35e6e936",
   "metadata": {},
   "source": [
    "# Python3入门到精通实战特训（第19期）第7课书面作业\n",
    "\n",
    "学号：116646\n",
    "\n",
    "**作业内容：**\n",
    "\n",
    "利用Mix-in技术实现一个双栖动物的类实现。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0ced8dcc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "survival|reproduction|swim|crawl\n",
      "I love water!\n"
     ]
    }
   ],
   "source": [
    "def mixin(pyClass, pyMixinClass, key=0):\n",
    "    if key:\n",
    "        pyClass.__bases__ = (pyMixinClass,) + pyClass.__bases__\n",
    "    elif pyMixinClass not in pyClass.__bases__:\n",
    "        pyClass.__bases__ += (pyMixinClass,)\n",
    "    else:\n",
    "        pass\n",
    "    \n",
    "class Animal:\n",
    "    def __init__(self):\n",
    "        self.category = \"animal\"\n",
    "        self.ability = 'survival|reproduction'\n",
    "        \n",
    "    def capability(self):\n",
    "        print(self.ability)\n",
    "        \n",
    "class Reptile(Animal):\n",
    "    def __init__(self):\n",
    "        super(Reptile,self).__init__()\n",
    "        self.sub_category = 'Reptile'\n",
    "        self.ability += '|crawl'\n",
    "        \n",
    "class Fish(Animal):\n",
    "    def __init__(self):\n",
    "        super(Fish,self).__init__()\n",
    "        self.sub_category = 'Fish'\n",
    "        self.ability += '|swim'\n",
    "    def flag(self):\n",
    "        print('I love water!')\n",
    "        \n",
    "class Frog(Reptile):\n",
    "    def __init__(self):\n",
    "        super(Frog,self).__init__()\n",
    "        self.sub_category = 'Frog'\n",
    "        \n",
    "mixin(Frog, Fish)\n",
    "\n",
    "frog = Frog()\n",
    "frog.capability()\n",
    "frog.flag()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6ebd4c9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
